'use strict';

const express = require('express');
const jade = require('jade');
const dbutility = require('../../common/dbutility');
const gputility = require('../../common/gputility');
const rdsutility = require('../../common/rdsutility');
const logger = require('../../common/logutility').logger('reTelName');
let router = express.Router();

router.get('/', function(req, res) {
    gputility.excuteGP(getGP(req, res));
});

function* getGP(req, res) {
    try {
        let tel4 = req.query.tel4;
        let reTelNames = yield rdsutility.getReTelNames(tel4);
        if(reTelNames.length>0){
            let html = jade.compileFile('./views/cou/reTelName.jade')({ rows: reTelNames });
            res.send(html);  
        }else{
            res.send(null);
        }
    } catch (e) {
        logger.error(e);
        res.redirect('/error');
    }
}

module.exports = router;